﻿<?php

if(!defined('IN_PHPSCUP'))exit('hacking'); 
class AlonepageApp extends BaseApp
{
    var $type = 'alonepage';
	
    function index()
    {

	    $TB_alonepage = &$this->_model('alonepage'); 	 
		
		$data = $TB_alonepage->show();
        $this->assign('lw_data', $data['data']);		
		$this->assign('lw_page', $data['page']);	
		   		
	 	$categorydata = & $GLOBALS['SCup']->_get_category_data($this->type);
		if(!is_array($categorydata))
		{
		 $categorydata = (array)$categorydata;
		}		
		$categorylist = array();
		foreach($categorydata as $value)
		{
		    $categorylist[$value['cat_id']] = $value['cat_name'];
		}		
		
        $this->assign('categorylist', $categorylist);							
	    
		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('alonepage_list.view.html');
    }

    function add()
    {	
	    $time = time();
		
		$data = array();
		
		$data['filename'] = $time.'.html' ;
        $this->assign('data', $data);	
    		
	 	$categorydata = & $GLOBALS['SCup']->_get_category_data($this->type);
		   
        $this->assign('categorydata', $categorydata);	
		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
        $this->assign('id','');		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('alonepage_add.view.html');	

    }
	
	
    function addpost()
    {

	     $data = $_POST['data'];

/*
         if(!isset($data['cat_id'])||empty($data['cat_id']))
		{
		 $notice = &get_message(array('msg'=>"所属栏目不能为空!",'url'=>'','title'=>'Notice'));
		 $notice ->display();		 
		 }	
*/	
         if(!isset($data['name'])||empty($data['name']))
		{
		 $notice = &get_message(array('msg'=>"单独页名称不能为空!",'url'=>'','title'=>'Notice'));
		 $notice ->display();		 
		 }	

		 $data['user_id'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];
		 		 
	     $data['filepath'] = '?app=alonepage&pa='.$data['filename'] ;		 
	 
		 $TB_alonepage = &$this->_model('alonepage'); 	 
		
		 $TB_alonepage->post($data);
	 
         $this->index();

    }

    function edit()
    {	
		$id = $_GET['id'];
		 $TB_alonepage = &$this->_model('alonepage'); 	 
		
		$data = $TB_alonepage->oneshow($id);
	 	$categorydata = & $GLOBALS['SCup']->_get_category_data($this->type);
		   
        $this->assign('categorydata', $categorydata);

	    $this->assign('data', $data);		
			
	    $this->assign('nav_lang', get_all_dirname(ROOT_PATH . '/languages'));	
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('alonepage_edit.view.html');
    }





    function editpost()
    {

	     $data = $_POST['data'];
		 /*
         if(!isset($data['cat_id'])||empty($data['cat_id']))
		{
		 $notice = &get_message(array('msg'=>"所属栏目不能为空!",'url'=>'','title'=>'Notice'));
		 $notice ->display();		 
		 }	
		 */

         if(!isset($data['name'])||empty($data['name']))
		{
		 $notice = &get_message(array('msg'=>"单独页名称不能为空!",'url'=>'','title'=>'Notice'));
		 $notice ->display();		 
		 }

		 $data['user_id'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];
		 		 
	     $data['filepath'] = '?app=alonepage&pa='.$data['filename'] ;
		 
		 $id = intval($data['id']);	 
		 

		 

		 $TB_alonepage = &$this->_model('alonepage'); 	 	 
		
		 $TB_alonepage->editaction($id,$data);
		 

		 $this->index();
		 

    }



    function del()
    {

	     $id = $_GET['id'];
		 $TB_alonepage = &$this->_model('alonepage'); 	 
		
		 $TB_alonepage->del($id); 
			 

		 $this->index();	  

    }



    function kindeditor()
    {
	 if(!isset($_GET['w']))
	 {
	 $_GET['w']='';
	 }
    $w = intval($_GET['w']);
    include(ROOT_PATH."/data/ewebeditor/ewebeditor.lib.php");		
	
	$kindeditor = new Ewebeditor(array('imageUploadCgi'=>SITE_URL.'/admin/index.php?app=alonepage&act=kindeditorupfile&w='.$w));
	$kindeditor->show();
	
    }
	
    function kindeditorupfile()
    {
	 if(!isset($_GET['w']))
	 {
	 $_GET['w']='';
	 }

    $w = intval($_GET['w']);
    include(ROOT_PATH."/data/ewebeditor/ewebeditor.lib.php");	
	
	$kindeditor = new Ewebeditor(array('imageUploadCgi'=>SITE_URL.'/admin/index.php?app=alonepage&act=kindeditorupfile&w='.$w));
	$kindeditor->upfile('alonepage/'.$w);
	
    }
	

    function cagryadd()
    {
		$GLOBALS['Lang']->_get_lang('alonepage');	
	    $category = & $GLOBALS['SCup']->_get_category();
		 		 		
		$catgydata = $category->show($this->type);
		
		$catgystr = $category->html_format_category($catgydata,0);	

        $this->assign('catgystr', $catgystr);	
		
        $this->assign('category_value', $this->type);
        $this->assign('appname', $this->type);			    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('cagryadd.view.html');
    }
	
    function editcatgy()
    {
		$GLOBALS['Lang']->_get_lang('alonepage');
		$id= intval($_GET['id']);
		
	    $category = & $GLOBALS['SCup']->_get_category();
		 		 		
		$catgydata = $category->show($this->type);
		
		$data = $category->oneshow($id);
		
		$catgystr = $category->html_format_category($catgydata,$data['parent_id'],0,0,$id);	
        $this->assign('appname', $this->type);
        $this->assign('data', $data);

        $this->assign('catgystr', $catgystr);
		
        $this->assign('category_value', $this->type);
			    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('cagryedit.view.html');
    }
	
    function cagrylist()
    {
		$GLOBALS['Lang']->_get_lang('alonepage');		
	    $category = & $GLOBALS['SCup']->_get_category();
		 		 		
		$catgydata = $category->show($this->type);
		$catgydata = $category->get_list_category($catgydata);

        $this->assign('appname', $this->type);		
        $this->assign('catgydata', $catgydata);				
        $this->assign('category_value', $this->type);
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('cagrylist.view.html');
    }

    function cyaddpost()
    {

	     $data = $_POST['data'];
         
		 $category = & $GLOBALS['SCup']->_get_category();
		 		 		
		 $category->post($data);
		 
		 $category->write_cache($this->type);	
		 	 		 
		 $this->cagrylist();

    }


    function cyeditpost()
    {

	     $id = $_POST['id'];

	     $data = $_POST['data'];
         
		 $category = & $GLOBALS['SCup']->_get_category();
		 		 		
		 $category->editaction($id,$data);

		 $category->write_cache($this->type);	
		 	 		 
		 $this->cagrylist();

    }

    function delcatgy()
    {
		$id= intval($_GET['id']);		

	    $category = & $GLOBALS['SCup']->_get_category();		 		 		
		$category->del($id);
		
		$category->write_cache($this->type);
				      
		$this->cagrylist();   
    }	
		
    function upfile()
    {
	 if(!isset($_POST["action"]))
	 {
	 $_POST["action"]='';
	 }
	 if(!isset($_GET['id']))
	 {
	 $_GET['id']='';
	 }
	 if(!isset($_GET["edit"]))
	 {
	 $_GET["edit"]='';
	 }	 
	 if(!isset($_GET["picurl"]))
	 {
	 $_GET["picurl"]='';
	 }			
		$action = $_POST["action"];
		
		$id = intval($_GET['id']);
		
		$edit = $_GET["edit"];
		$picurl = $_GET["picurl"];
		if($edit)
		{
        $this->assign('edit', $edit);		
		}
        if($picurl)
		{
        $this->assign('picurl', $picurl);
		}

						
		if($action == 'post')
		{
				if(!$_FILES['postfile1']['tmp_name']){
					$id || $id = intval($_POST['id']);	
					echo '<script> alert("请选择上传的图片");</script>';	
				}else{
	        if(!isset($_POST["edit"]))
	        {
	         $_POST["edit"]='';
	        }	 
	        if(!isset($_POST["picurl"]))
	        {
	         $_POST["picurl"]='';
	        }
	       if(!isset($_POST['id']))
	       {
	        $_POST['id']='';
	        }			
		       $edit = $_POST["edit"];
		       $picurl = $_POST["picurl"];
		 	   $id || $id = intval($_POST['id']);		

		       include(ROOT_PATH.'/lib/upfile.lib.php');	  
	           $upfile = new Upfile('alonepage/'.$id); 	  
	           $updata = $upfile->_batch_upfile('alonepage');		 

		       $newfile = $updata[1]['path'];
		       
			   if($edit=='editp' && $picurl)
			   {
			   
/*			          $TB_new = &$this->_model('alonepage');			    		 		 		
		              $TB_new->editpicurl($id,array('picurl'=>$newfile));*/
					  
		              $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
			          if(!is_dir($pic_dir)&&file_exists($pic_dir))
		              {
		               del_file($pic_dir);	
		              }						  
			   }
			   
			    if($edit=='edit' && $picurl)
		       {
		              $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
			          if(!is_dir($pic_dir)&&file_exists($pic_dir))
		              {
		               del_file($pic_dir);	
		              }				 
		       }
		 	   
			
		
		      $pic_url = SITE_URL . '/' . UPFILE_PATH . '/' .$newfile;

			 echo "<A HREF='?app=alonepage&act=upfile&edit=edit&picurl=$newfile&id=$id'>修改图片</A>";
	     
		$jsfun="upfile";
	    echo "<script>
				if(self==top){
					window.opener.$jsfun('$newfile','uppic');
					window.self.close();
				}else{
					window.parent.$jsfun('$newfile','uppic');
				}
		     </script>";
				
	    exit;
		
			}
		}

        $this->assign('id', $id);
	    $this->assign('app', $this->type);					    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
        $this->assign('alldirpicurl',ROOT_PATH.'/'.UPFILE_PATH.'/'.$picurl);
		
        $this->assign('site_url',SITE_URL);
        $this->assign('edit',$edit);
        $this->assign('picurl',$picurl);		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('upfile.view.html');
    }



  
}

?>